package com.haoze.nurseapp.dao;

import com.haoze.common.mapper.MyMapper;
import com.haoze.nurseapp.dto.*;
import com.haoze.nurseapp.dto.order.PrintPatientOrderDTO;
import com.haoze.nurseapp.dto.order.PrintPatientOrderQueryDTO;
import com.haoze.nurseapp.model.*;
import com.haoze.repository.model.HspBasicValueEntity;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface PatientOrderMapper extends MyMapper<PatientOrdersEntity> {


    List<OrderElementDTO> orderElements(@Param("dictName") String dictName);

    List<Map<String, Object>> createEmrFileData(@Param("tplId") String tplId);

    EmrFileIndexEntity getEmrFileByOrder(@Param("orderId") String orderId);

    void submitOrders(@Param("orderIds") List<String> orderIds);

    void dataCodeNoIncrement(@Param("dataCodeId") String dataCodeId);

    Map<String, String> getOrderReqNum(@Param("tName") String tName);

    String getOrderDictType(@Param("dataValue") String dataValue);

    String getOrderDictTypeName(@Param("dataValue") String dataValue);

    Map<String, String> getCtlTplByDict(@Param("ctlId") String ctlId);

    Map<String, String> getCtlTplByTplId(@Param("tplId") String tplId);

    Map<String, String> getCatalogTplByTplId(@Param("tplId") String tplId);

    Map<String, String> getOperDataByElement(@Param("dictId") String dictId, @Param("fieldName") String fieldName);

    Map<String, String> getDictDataByElement(@Param("dictId") String dictId, @Param("fieldName") String fieldName);

    Map<String, String> getServiceDataByElement(@Param("dictId") String dictId, @Param("fieldName") String fieldName);

    List<OrderTypeDTO> getOrderTypes();

    List<OrderTypeDTO> getDictsByOrderType(@Param("id") String id, @Param("ctlCode") String ctlCode);

    List<OrderTypeDTO> getExamClass(@Param("id") String id, @Param("ctlCode") String ctlCode, @Param("areaId") String area);

    List<OrderTypeDTO> getExamSubClass(@Param("id") String id, @Param("ctlCode") String ctlCode);

    List<OrderTypeDTO> getExamItemBySubClass(@Param("id") String id, @Param("ctlCode") String ctlCode);

    int countOrderChildren(@Param("id") String id, @Param("ctlCode") String ctlCode);

    List<OrderTypeDTO> queryDictsByOrderType(@Param("queryString") String queryString, @Param("userId") String userId, @Param("ctlCode") String ctlCode, @Param("areaId") String areaId);

    List<OrderItemDTO> queryOrderCtls(@Param("ctlIdList") List<String> ctlIdList);

    HspBasicValueEntity getDataValueById(@Param("valueId") String valueId);

    /**
     * 查询当前用户
     *
     * @param userId
     * @return
     */
    Map<String, String> getUser(@Param("userId") String userId);

    /**
     * 更新前记录
     *
     * @param emrFileId
     */
    void recordBeforeUpdate(@Param("emrFileId") String emrFileId);


    void removeDeletedNodes(@Param("emrFileId") String emrFileId, @Param("dataVersion") Integer dataVersion);

    /**
     * 新旧数据比较
     *
     * @param emrFileId
     * @param fileIndexDataMarkId
     * @param doctorId
     */
    void compareAfterUpdate(@Param("emrFileId") String emrFileId,
                            @Param("fileIndexDataMarkId") String fileIndexDataMarkId,
                            @Param("doctorId") String doctorId);

    String getSysElementIdByVarCode(String varCode);

    List<String> getOrderIdElemetId();

    //医嘱下达起始任务节点
    TaskNodeEntity getOrderBeginTaskNode();
    //任务执行节点绑定的模板数据元集
    List<FileIndexDataEntity> getFileIndexDataByTaskNode(@Param("taskNodeId") String taskNodeId);
    //查询任务执行所有节点对应的医嘱文书数据元
    List<FileIndexDataDTO> getAllFileIndexDataByTask(@Param("taskExecuteId") String taskExecuteId, @Param("executeDetailId") String executeDetailId);
    //查询任务节点条件明细数据元
    List<ConditionDetailsDTO> getConditionElements(@Param("taskNodeId") String taskNodeId);
    /**
     * 根据电子申请单编号查询医嘱id
     * @param reqNum
     * @return
     */
    String findInpatOrderDataId(@Param("reqNum") String reqNum);


    /**
     * 根据电子申请单编号和序号查询医嘱id
     * @param reqNum
     * @return
     */
    String findInpatOrderDataIdBySerialNum(@Param("reqNum") String reqNum, @Param("serialNum") String serialNum);


    /**
     * 根据医嘱和科室编码查询需要执行的流程节点
     * @param inpatOrderDataId
     * @param deptCodes
     * @return
     */
    List<TaskExecuteDetailEntity> findExecuteDetails(@Param("inpatOrderDataId") String inpatOrderDataId, @Param("deptCodes") List<String> deptCodes);

    /**
     *根据taskExecuteDetailId 获取执行节点信息
     * @param taskExecuteDetailIds
     * @return
     */
    List<ProcessExecuteNodeDTO> findExecuteNodeInfos(@Param("ids") List<String> taskExecuteDetailIds);

    List<PatientOrderDTO> orderList(@Param("inpatNum") String inpatNum, @Param("type") String type, @Param("queryString") String queryString,
                                    @Param("ordersClass") String ordersClass, @Param("itemClassId") String itemClassId, @Param("basicdatavalIds") String basicdatavalIds);

    int orderListCount(@Param("inpatNum") String inpatNum, @Param("type") String type);

    List<PatientOrderDTO> subOrderList(@Param("inpatNum") String inpatNum, @Param("orderNo") String orderNo);

    List<PatientOrderDTO> saveOrderList(@Param("inpatNum") String inpatNum);

    List<Map<String, String>> saveOrderFileIds(@Param("inpatNum") String inpatNum);

    int countSaveOrderFile(@Param("inpatNum") String inpatNum);

    void updateOrderFileSave(@Param("orderIds") List<String> orderIds);

    void updateOrderSave(@Param("orderIds") List<String> orderIds);

    void delOrderFile(@Param("orderFileIds") List<String> orderFileIds);

    void delOrders(@Param("orderFileIds") List<String> orderFileIds);

    void recoverOrderFile(@Param("orderIds") List<String> orderIds);

    List<PatientOrderDTO> cancelOrderList(@Param("inpatNum") String inpatNum);
    //历史医嘱
    List<PatientOrderDTO> historyOrderList(@Param("inpatNum") String inpatNum, @Param("queryString") String queryString, @Param("ordersClass") String ordersClass, @Param("itemClassId") String itemClassId);

    /**
     * 获取药物频次配置
     * @param dataCode
     * @return
     */
    String getCronDescriber(@Param("dataCode") String dataCode);

    /**
     * 常用
     * 获取药物频次配置
     * @param dataCode
     * @return
     */
    String getFreqCommon(@Param("dataCode") String dataCode, @Param("administrationId") String administrationId);

    List<Map<String, String>> getFileDataOrderMappings(@Param("emrFileId") String emrFileId);

    /**
     * 查询主医嘱
     * @param orderDataId
     * @return
     */
    PatientOrdersEntity findPrimaryOder(@Param("orderDataId") String orderDataId);

    int getMaxOrderNo(@Param("inpatNum") String inpatNum);

    int getMaxPrescNo(@Param("inpatNum") String inpatNum);

    String getOrderCurrentNode(@Param("orderId") String orderId);

    Map<String, String> getOrderDataByFileData(@Param("emrFileId") String emrFileId, @Param("fileDataId") String fileDataId,
                                               @Param("elementId") String elementId, @Param("fields") List<String> fields);

    /**
     * 查询用户id
     * @param empNo
     * @return
     */
    String findUserIdByNo(@Param("empNo") String empNo);

    List<Map<String, Object>> getOrderProcess(@Param("orderId") String orderId);

    List<Map<String, Object>> getOrderTpl(@Param("userId") String userId, @Param("list") List<FileIndexDataDTO> elements);

    List<String> getOrderTplDetailId(@Param("tplId") String tplId);

    List<String> getOrderTplDetailValue(@Param("tplId") String tplId, @Param("tplDetailId") String tplDetailId);

    String getOrderTplRootId(@Param("tplId") String tplId, @Param("tplDetailId") String tplDetailId);

    String getOrderTplDataValueByElement(@Param("tplId") String tplId, @Param("elementId") String elementId, @Param("tplDetailId") String tplDetailId);

    String getOrderStartDate(@Param("emrFileId") String emrFileId);

    String getOrderExeDept(@Param("orderId") String orderId);

    List<Map<String, String>> getOrderField(@Param("tName") String tName);

    List<String> getOrderReqField();

    List<OrderElementDataDTO> getOrderElementDataValue(@Param("tName") String tName, @Param("idField") String idField, @Param("dictId") String dictId,
                                                       @Param("fields") List<String> fields, @Param("exeDeptId") String exeDeptId);

    List<Map<String, String>> getServiceExeDept(@Param("dictId") String dictId);

    int countUnExeTaskExecuteDetail(@Param("orderId") String orderId, @Param("taskId") String taskId);

    void batchConfirmOrder(@Param("inpatNum") String inpatNum);

    String getReqNumByExamReport(@Param("rowId") String rowId);

    String getReqNumByLabReport(@Param("rowId") String rowId);

    String getItemCodeById(@Param("itemId") String itemId);

    Map<String, String> getDrugCodeById(@Param("drugId") String drugId);

    Map<String,String> getTransfusionSafe(@Param("dictId") String dictId);

    List<String> getOrderExecuteEmrFile(@Param("inpatNum") String inpatNum, @Param("userId") String userId);

    void recoverOrderByTaskFileId(@Param("emrFileId") String emrFileId);

    void recoverOrderFileByTaskFileId(@Param("emrFileId") String emrFileId);

    void delOrderTaskExecute(@Param("taskExecuteId") String taskExecuteId);

    int countPathogenLabReport(@Param("inpatNum") String inpatNum);

    List<Map<String, String>> getOrderInfoById(@Param("orderIds") List<String> orderIds);

    Map<String, String> convertOrderElementDataValue(@Param("emrFileId") String emrFileId, @Param("fileDataId") String fileDataId,
                                                     @Param("elementId") String elementId, @Param("fields") List<String> fields, @Param("tableName") String tableName);

    Map<String, String> convertPatientOrderPrint(@Param("emrFileId") String emrFileId, @Param("fileDataId") String fileDataId,
                                                 @Param("elementId") String elementId, @Param("fields") List<String> fields, @Param("tName") String tName);

    Map<String, String> conOrderPrint(@Param("emrFileId") String emrFileId, @Param("fields") List<String> fields, @Param("tName") String tName);

    void updateOrderReqNum(@Param("reqNum") String reqNum, @Param("primaryId") String primaryId);

    void delOrderReqNum(@Param("reqNum") String reqNum);

    void saveOrderReqInfo(@Param("reqDataId") String reqDataId, @Param("primaryId") String primaryId);

    void saveOrderReqItemInfo(@Param("reqDataItemId") String reqDataItemId, @Param("primaryId") String primaryId);

    void saveOrderInfo(@Param("orderId") String orderId, @Param("primaryId") String primaryId);

    String getRelatedOrderNo(@Param("orderId") String orderId);

    String getDataValueByOrderVarCode(@Param("orderId") String orderId, @Param("varCode") String varCode);

    List<OrderTypeDTO> getDeptDictsByUserId(@Param("userId") String userId);


    List<Map<String, String>> queryOrderTypes();

    int queryHzDept(@Param("varCode") String varCode, @Param("inpatNum") String inpatNum, @Param("deptIds") List<String> deptIds);


    int queryDrugToxByIds(@Param("drugIds") List<String> drugIds, @Param("toxList") List<String> toxList);

    String getFreCodeById(@Param("freqId") String freqId);

    Map<String,String> getDeptCodeByInpatNum(String inpatNum);

    Map<String, String> getSysElementIdByParams(@Param("varCodes") List<String> varCodeParams);

    /**
     * 医嘱查询打印
     * @param queryDto
     * @return
     */
    List<PrintPatientOrderDTO>  queryPrintPatientOrders(PrintPatientOrderQueryDTO queryDto);


    List<PrintPatientOrderDTO> queryPrintSubOrderList(@Param("inpatNum") String inpatNum, @Param("orderNo") String orderNo);

    List<PatientOrdersEntity> selectOrderByEmrFileId(@Param("emrFileId") String emrFileId);

    List<Map<String,String>> selectTransfer(@Param("inpatNum") String inpatNum);

    List<Map<String,String>> selectPrintItemDate(@Param("type") String type, @Param("itemClassId") String itemClassId, @Param("inpatNum") String inpatNum);

    List<Map<String,String>> selectPrint(@Param("type") String type, @Param("inpatNum") String inpatNum);

    String selectOrderBedNo(@Param("inpatNum") String inpatNum);

    String selectPrintDrug(@Param("itemId") String itemId);

    List<PatientOrdersEntity> getEnableStopOrders(@Param("inpatNum") String inpatNum);

    void stopAllPatientOrders(@Param("inpatNum") String inpatNum, @Param("userId") String userId, @Param("stopDateTime") Date stopDateTime);

    void updateOrderEndDateTime(@Param("inpatNum") String inpatNum, @Param("orderNo") Integer orderNo);

    Map<String, String> getUserByPersonId(String auditUserId);

    TaskNodeEntity getPrescBeginTaskNode();

    List<Map<String,String>> getConsultation(@Param("elementId") String elementId, @Param("tableName") String tableName, @Param("emrFileId") String emrFileId);

    List<PatientPrescEntity> selectPrescByEmrFileId(@Param("emrFileId") String emrFileId);

    void recoverPrescByTaskFileId(@Param("emrFileId") String emrFileId);

    void batchInsertDayRoomOrders(@Param("inpatNum") String inpatNum, @Param("outpatNums") List<String> outpatNum);

    void batchUpdateDayRoomReq(@Param("inpatNum") String inpatNum, @Param("outpatNums") List<String> outpatNum);

    Map<String, String> getOrderDrugInfo(@Param("inpatOrderDataId") String inpatOrderDataId);

    void updateTranRecordAuditFileId(@Param("reqNum") String reqNum, @Param("emrFileId") String emrFileId);

    List<OrderTypeDTO> getSubjectDicts(@Param("userId") String userId, @Param("id") String id);

    List<OrderTypeDTO> getTemplatesByCtlId(@Param("ctlId") String id);

    List<Integer> getOrderNosByInpatNum(@Param("inpatNum") String inpatNum);

    void updateOrderNo(@Param("orderNo") Integer orderNo, @Param("inpatOrderDataId") String inpatOrderDataId);

    Integer selectOrderCount(@Param("inpatNum") String inpatNum, @Param("orderNo") Integer orderNo, @Param("orderSubNo") Integer orderSubNo);

    Integer getTransfusionSum(@Param("inpatNum") String inpatNum, @Param("newPlanBeginDate") Date newPlanBeginDate);

    List<FileIndexDataDTO> getAllFileIndexDataByTaskForNurse(@Param("taskBatchId") String taskBatchId);

    String getBloodCateType(@Param("bloodId") String bloodId);

    void updatePrintStatus(@Param("approvalNums") List<String> approvalNums);

    List<OrderTypeDTO> getDrugDicts(@Param("id") String id);

    String queryIsSyxs(@Param("id") String taskExeDetailId,@Param("orderQrCode") String orderQrCode);
}